package com.baobao.domain;

import java.io.Serializable;

import java.lang.StringBuilder;

import java.util.Calendar;

import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import javax.xml.bind.annotation.*;

import javax.persistence.*;

/**
 */
@IdClass(com.baobao.domain.ChatPK.class)
@Entity
@NamedQueries({
		@NamedQuery(name = "findAllChats", query = "select myChat from Chat myChat"),
		@NamedQuery(name = "findChatByDate", query = "select myChat from Chat myChat where myChat.date = ?1"),
		@NamedQuery(name = "findChatByPrimaryKey", query = "select myChat from Chat myChat where myChat.sender = ?1 and myChat.receiver = ?2 and myChat.date = ?3"),
		@NamedQuery(name = "findChatByMaxDateAndPhone", query = "select myChat from Chat myChat where myChat.date=(select max(myChat_1.date) from Chat myChat_1 where myChat_1.sender = ?1 and myChat_1.receiver = ?2)"),
		@NamedQuery(name = "findChatByReceiver", query = "select myChat from Chat myChat where myChat.receiver = ?1"),
		@NamedQuery(name = "findChatByReceiverContaining", query = "select myChat from Chat myChat where myChat.receiver like ?1"),
		@NamedQuery(name = "findChatBySender", query = "select myChat from Chat myChat where myChat.sender = ?1"),
		@NamedQuery(name = "findChatBySenderContaining", query = "select myChat from Chat myChat where myChat.sender like ?1"),
		@NamedQuery(name = "findChatByStatus", query = "select myChat from Chat myChat where myChat.status = ?1"),
		@NamedQuery(name = "findChatByStatusContaining", query = "select myChat from Chat myChat where myChat.status like ?1"),
		@NamedQuery(name = "findChatByText", query = "select myChat from Chat myChat where myChat.text = ?1"),
		@NamedQuery(name = "findChatByTextContaining", query = "select myChat from Chat myChat where myChat.text like ?1"),
		@NamedQuery(name = "findChatByPhoneAndStatus", query = "select myChat from Chat myChat where myChat.sender = ?1 and myChat.receiver = ?2 and myChat.status = ?3"),
		@NamedQuery(name = "findChatByReceiverAndLatestMsgnum", query = "select myChat from Chat myChat where myChat.receiver = ?1 and myChat.date > ?2 order by myChat.date desc"),
		@NamedQuery(name = "findChatByUniqueId", query = "select myChat from Chat myChat where myChat.uniqueId = ?1") })



@Table(catalog = "baobaodb", name = "chat")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "bb/com/baobao/domain", name = "Chat")
public class Chat implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "sender", length = 40, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@XmlElement
	String sender;
	/**
	 */

	@Column(name = "receiver", length = 40, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@XmlElement
	String receiver;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@XmlElement
	Calendar date;
	/**
	 */

	@Column(name = "status", length = 10, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String status;
	/**
	 */

	@Column(name = "text", length = 3000, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String text;
	/**
	 */

	@Column(name = "uniqueId", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer uniqueId;

	/**
	 */
	public void setSender(String sender) {
		this.sender = sender;
	}

	/**
	 */
	public String getSender() {
		return this.sender;
	}

	/**
	 */
	public void setReceiver(String receiver) {
		this.receiver = receiver;
	}

	/**
	 */
	public String getReceiver() {
		return this.receiver;
	}

	/**
	 */
	public void setDate(Calendar date) {
		this.date = date;
	}

	/**
	 */
	public Calendar getDate() {
		return this.date;
	}

	/**
	 */
	public void setStatus(String status) {
		this.status = status;
	}

	/**
	 */
	public String getStatus() {
		return this.status;
	}

	/**
	 */
	public void setText(String text) {
		this.text = text;
	}

	/**
	 */
	public String getText() {
		return this.text;
	}

	/**
	 */
	public void setUniqueId(Integer uniqueId) {
		this.uniqueId = uniqueId;
	}

	/**
	 */
	public Integer getUniqueId() {
		return this.uniqueId;
	}

	/**
	 */
	public Chat() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(Chat that) {
		setSender(that.getSender());
		setReceiver(that.getReceiver());
		setDate(that.getDate());
		setStatus(that.getStatus());
		setText(that.getText());
		setUniqueId(that.getUniqueId());
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("sender=[").append(sender).append("] ");
		buffer.append("receiver=[").append(receiver).append("] ");
		buffer.append("date=[").append(date).append("] ");
		buffer.append("status=[").append(status).append("] ");
		buffer.append("text=[").append(text).append("] ");
		buffer.append("uniqueId=[").append(uniqueId).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((sender == null) ? 0 : sender.hashCode()));
		result = (int) (prime * result + ((receiver == null) ? 0 : receiver.hashCode()));
		result = (int) (prime * result + ((date == null) ? 0 : date.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Chat))
			return false;
		Chat equalCheck = (Chat) obj;
		if ((sender == null && equalCheck.sender != null) || (sender != null && equalCheck.sender == null))
			return false;
		if (sender != null && !sender.equals(equalCheck.sender))
			return false;
		if ((receiver == null && equalCheck.receiver != null) || (receiver != null && equalCheck.receiver == null))
			return false;
		if (receiver != null && !receiver.equals(equalCheck.receiver))
			return false;
		if ((date == null && equalCheck.date != null) || (date != null && equalCheck.date == null))
			return false;
		if (date != null && !date.equals(equalCheck.date))
			return false;
		return true;
	}
}
